home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / libgrx / ndrivers / vesainfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-31  |  5.4 KB  |  171 lines

  1. /**
  2.  ** VESAINFO.C ---- test program to print VESA BIOS information
  3.  **
  4.  ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5.  ** Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6.  ** Copyright (C) 1993 Grzegorz Mazur, gbm@ii.pw.edu.pl
  7.  **
  8.  ** This file is distributed under the terms listed in the document
  9.  ** "copying.dj", available from DJ Delorie at the address above.
  10.  ** A copy of "copying.dj" should accompany this file; if not, a copy
  11.  ** should be available from where this file was obtained.  This file
  12.  ** may not be distributed without a verbatim copy of "copying.dj".
  13.  **
  14.  ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15.  ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16.  **/
  17.  
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <dos.h>
  21.  
  22. #include "pieces/vesainfo.c"
  23.  
  24. void printinfo(VgaInfoBlock *vgainfo)
  25. {
  26.     char  far *sp = vgainfo->OEMStringPtr;
  27.     short far *mp = vgainfo->VideoModePtr;
  28.  
  29.     printf("VESASignature:\t\"%c%c%c%c\"\n",
  30.         vgainfo->VESASignature[0],
  31.         vgainfo->VESASignature[1],
  32.         vgainfo->VESASignature[2],
  33.         vgainfo->VESASignature[3]
  34.     );
  35.     printf("VESAVersion:\t%d.%d\n",
  36.         VESA_VERSION_MAJOR(VESAversion),
  37.         VESA_VERSION_MINOR(VESAversion)
  38.     );
  39.     printf("OEMStringPtr:\t\"");
  40.     while(*sp != '\0') putchar(*sp++);
  41.     printf("\"\nCapabilities:\t%ld\n",vgainfo->Capabilities);
  42.     printf("VideoModePtr:\t%Fp\n",mp);
  43.     printf("Video Modes:\t");
  44.     while(*mp != (-1)) printf("0x%x ",*mp++);
  45.     printf("\n");
  46.     if(VESAversion >= VESA_VERSION(1,2)) {
  47.         printf("Memory Size:\t%d*64KBytes\n",vgainfo->MemorySize);
  48.     }
  49.     printf("\n");
  50.  
  51. }
  52.  
  53. #define DEFBIT(bit)    { bit, #bit }
  54. typedef struct {
  55.     int  bit;
  56.     char *name;
  57. } bitdef;
  58.  
  59. bitdef modeattrbits[] = {
  60.     DEFBIT(MODE_SUPPORTED),
  61.     DEFBIT(MODE_EXTINFO),
  62.     DEFBIT(MODE_SUPBIOS),
  63.     DEFBIT(MODE_ISCOLOR),
  64.     DEFBIT(MODE_ISGRAPHICS),
  65.     { 0 }
  66. };
  67.  
  68. bitdef winattrbits[] = {
  69.     DEFBIT(WIN_SUPPORTED),
  70.     DEFBIT(WIN_READABLE),
  71.     DEFBIT(WIN_WRITABLE),
  72.     { 0 }
  73. };
  74.  
  75. bitdef memorymodels[] = {
  76.     DEFBIT(MODEL_TEXT),
  77.     DEFBIT(MODEL_CGA),
  78.     DEFBIT(MODEL_HERC),
  79.     DEFBIT(MODEL_4PLANE),
  80.     DEFBIT(MODEL_PACKED),
  81.     DEFBIT(MODEL_256_NC),
  82.     DEFBIT(MODEL_DIRECT),
  83.     { 0 }
  84. };
  85.  
  86. void printbits(int value,bitdef *def)
  87. {
  88.     int prev = 0;
  89.  
  90.     while(def->bit != 0) {
  91.         if(value & def->bit) {
  92.         if(prev) printf(" | ");
  93.         printf(def->name);
  94.         prev = 1;
  95.         }
  96.         def++;
  97.     }
  98.     if(!prev) printf("0");
  99.     printf("\n");
  100. }
  101.  
  102. char *getmodelname(int model)
  103. {
  104.     static char temp[50];
  105.  
  106.     if(model < 0) return(sprintf(temp,"Invalid model [%d]",model),temp);
  107.     if(model <= MODEL_DIRECT) return(memorymodels[model].name);
  108.     if(model <= 15) return(sprintf(temp,"VESA model [0x%02x]",model),temp);
  109.     return(sprintf(temp,"OEM model [%0x2x]",model),temp);
  110. }
  111.  
  112. void printmodeinfo(int mode,ModeInfoBlock *modeinfo)
  113. {
  114.     printf("Mode 0x%x is supported\n",mode);
  115.     printf("  ModeAttributes:   ");
  116.     printbits(modeinfo->ModeAttributes,modeattrbits);
  117.     printf("  WinAAttributes:   ");
  118.     printbits(modeinfo->WinAAttributes,winattrbits);
  119.     printf("  WinBAttributes:   ");
  120.     printbits(modeinfo->WinBAttributes,winattrbits);
  121.     printf("  WinGranularity:   %d\n",modeinfo->WinGranularity);
  122.     printf("  WinSize:          %d\n",modeinfo->WinSize);
  123.     printf("  WinASegment:      0x%04x\n",modeinfo->WinASegment);
  124.     printf("  WinBSegment:      0x%04x\n",modeinfo->WinBSegment);
  125.     printf("  WinFuncPtr:       \%Fp\n",modeinfo->WinFuncPtr);
  126.     printf("  BytesPerScanLine: %d\n",modeinfo->BytesPerScanLine);
  127.     if(!(modeinfo->ModeAttributes & MODE_EXTINFO)) return;
  128.     printf("  XResolution:      %d\n",modeinfo->XResolution);
  129.     printf("  YResolution:      %d\n",modeinfo->YResolution);
  130.     printf("  XCharSize:        %d\n",modeinfo->XCharSize);
  131.     printf("  YCharSize:        %d\n",modeinfo->YCharSize);
  132.     printf("  NumberOfPlanes:   %d\n",modeinfo->NumberOfPlanes);
  133.     printf("  BitsPerPixel:     %d\n",modeinfo->BitsPerPixel);
  134.     printf("  NumberOfBanks:    %d\n",modeinfo->NumberOfBanks);
  135.     printf("  MemoryModel:      %d (%s)\n",modeinfo->MemoryModel,getmodelname(modeinfo->MemoryModel));
  136.     printf("  BankSize:         %d\n",modeinfo->BankSize);
  137.     printf("  NumImagePages     %d\n",modeinfo->NumImagePages);
  138.     if(VESAversion < VESA_VERSION(1,2)) return;
  139.     printf("  RedMaskSize:      %d\n",modeinfo->RedMaskSize);
  140.     printf("  RedMaskPos:       %d\n",modeinfo->RedMaskPos);
  141.     printf("  GreenMaskSize:    %d\n",modeinfo->GreenMaskSize);
  142.     printf("  GreenMaskPos:     %d\n",modeinfo->GreenMaskPos);
  143.     printf("  BlueMaskSize:     %d\n",modeinfo->BlueMaskSize);
  144.     printf("  BlueMaskPos:      %d\n",modeinfo->BlueMaskPos);
  145.     printf("  ReservedMaskSize: %d\n",modeinfo->ReservedMaskSize);
  146.     printf("  ReservedMaskPos:  %d\n",modeinfo->ReservedMaskPos);
  147.     printf("  DirectScreenMode: %d\n",modeinfo->DirectScreenMode);
  148. }
  149.  
  150. void main(void)
  151. {
  152.     VgaInfoBlock  *vb;
  153.     ModeInfoBlock *mb;
  154.     if((vb = VESAgetInfo()) != NULL) {
  155.         static short modes[1000];
  156.         short far *modeptr = vb->VideoModePtr;
  157.         short *mdp = modes;
  158.         int mode;
  159.         printinfo(vb);
  160.         while((*mdp++ = *modeptr++) != (-1)) ;
  161.         mdp = modes;
  162.         while((mode = *mdp++) != (-1)) {
  163.         if((mb = VESAgetModeInfo(mode)) != NULL) printmodeinfo(mode,mb);
  164.         else printf("Mode 0x%x IS NOT SUPPORTED!\n",mode);
  165.         }
  166.     }
  167.     else printf("VESA BIOS extensions not found\n");
  168.     exit(0);
  169. }
  170.  
  171.